namespace PMS.Common
{
    using System;
    using System.IO;

    public class FileConverter
    {
        public static byte[] ConvertStreamToByteBuffer(Stream theStream)
        {
            int num;
            MemoryStream stream = new MemoryStream();
            while ((num = theStream.ReadByte()) != -1)
            {
                stream.WriteByte((byte) num);
            }
            return stream.ToArray();
        }

        public static byte[] GetBinaryFile(string filename)
        {
            if (File.Exists(filename))
            {
                try
                {
                    using (FileStream stream = File.OpenRead(filename))
                    {
                        return ConvertStreamToByteBuffer(stream);
                    }
                }
                catch (Exception)
                {
                    return new byte[0];
                }
            }
            return new byte[0];
        }
    }
}

